gh-140746: Fix Thread.start() that can hang indefinitely#140799
Open
ryv-odoo wants to merge 12 commits intopython:mainfrom
Open
gh-140746: Fix Thread.start() that can hang indefinitely#140799ryv-odoo wants to merge 12 commits intopython:mainfrom
ryv-odoo wants to merge 12 commits intopython:mainfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a new thread is started (
Thread.start()), the current thread waits for the new thread's_startedsignal (self._started.wait()). If the new thread doesn't have enough memory, it might crash before signaling its start to the parent thread, causing the parent thread to wait indefinitely (still inThread.start()).To fix the issue, remove the _started python attribute from the Thread class and converted the logic at C level (PyEvent). A flaw of this method, it that the threading module will still contains the zombie thread into the _limbo dictionnary.
We also change
Thread._delete()to usepopto remove the thread from_active, as there is no guarantee that the thread exists in_active[get_ident()], thus avoiding a potentialKeyError. This can happen if_bootstrap_innercrashes before_active[self._ident] = selfexecutes. We useself._identbecause we knowset_ident()has already been called.Moreover, remove the old comment in
_deletebecause_active_limbo_lockbecame reentrant in commit 243fd01.Not sure if this fix need/can to be backported